using System;
using System.Collections.Generic;
using System.Text;
using Jbe.TestSuite.Infrastructure.Interface.Services;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using Microsoft.Practices.CompositeUI.Utility;

namespace Jbe.TestSuite.Infrastructure.Module.Services
{
    public class WinFormsCreationService : IUIElementCreationService 
    {
        public IMenuItem CreateMenuItem()
        {
            return new WinFormsMenuItem();
        }

        public IMenuItem CreateMenuItem(string text)
        {
            return new WinFormsMenuItem(text);
        }

        public IMenuItem CreateMenuItem(string text, Image image)
        {
            return new WinFormsMenuItem(text, image);
        }

        public IToolBar CreateToolBar()
        {
            return new WinFormsToolBar();
        }

        public IToolBar CreateToolBar(params IToolBarItem[] items)
        {
            return new WinFormsToolBar(items);
        }

        public IToolBarItem CreateToolBarItem()
        {
            return new WinFormsMenuItem();
        }

        public IToolBarItem CreateToolBarItem(string text)
        {
            return new WinFormsMenuItem(text);
        }

        public IToolBarItem CreateToolBarItem(string text, Image image)
        {
            return new WinFormsMenuItem(text, image);
        }
    }

    internal sealed class WinFormsMenuItem : ToolStripMenuItem, IMenuItem, IToolBarItem 
    {
        public WinFormsMenuItem() { }

        public WinFormsMenuItem(string text) : base(text) { }
        
        public WinFormsMenuItem(string text, Image image) : base(text, image) { }
    }

    internal sealed class WinFormsToolBar : ToolStrip, IToolBar 
    {
        private IList<IToolBarItem> menuItems;

        public WinFormsToolBar() : this(null) { }
        
        public WinFormsToolBar(params IToolBarItem[] items) 
        {
            menuItems = new MenuItemCollection(base.Items);
            foreach (IToolBarItem item in items)
            {
                menuItems.Add(item);
            }
        }

        public new IList<IToolBarItem> Items
        {
            get { return menuItems; }
        }
    }
}
